import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;

public class FileSceneSaver implements ISceneSaver {

    @Override
    public Object load(String name) {
        FileInputStream fileInputStream = null;
        ObjectInputStream objectInputStream = null;
        try {
            File file = new File(name);
            fileInputStream = new FileInputStream(file);
            objectInputStream = new ObjectInputStream(fileInputStream);
            return objectInputStream.readObject();
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(FileSceneSaver.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(FileSceneSaver.class.getName()).log(Level.SEVERE, null, ex);
        } 
        finally {
            try {
                fileInputStream.close();
                objectInputStream.close();
            } catch (IOException ex) {
                Logger.getLogger(FileSceneSaver.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        return null;
    }

    @Override
    public boolean write(String name, Object object) {
        FileOutputStream fileOutputStream = null;
        ObjectOutputStream objectOutputStream = null;
        try {
            File file = new File(name);
            fileOutputStream = new FileOutputStream(file);
            objectOutputStream = new ObjectOutputStream(fileOutputStream);
            objectOutputStream.writeObject(object);
            return true;
        } catch (IOException ex) {
            Logger.getLogger(FileSceneSaver.class.getName()).log(Level.SEVERE, null, ex);
            try {
                fileOutputStream.close();
                objectOutputStream.close();
            } catch (IOException ex1) {
                Logger.getLogger(FileSceneSaver.class.getName()).log(Level.SEVERE, null, ex1);
            }
        } 
        return false;
    }
}
